package com.ouheng.shop.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ouheng.shop.dao.CouponDao;
import com.ouheng.shop.dao.VolumeActivityDao;
import com.ouheng.shop.domain.CouponDO;
import com.ouheng.shop.domain.VolumeActivityDO;
import com.ouheng.shop.service.VolumeActivityService;



@Service
public class VolumeActivityServiceImpl implements VolumeActivityService {
	@Autowired
	private VolumeActivityDao volumeActivityDao;
	
	@Autowired
	private CouponDao couponDao;
	
	
	
	@Override
	public VolumeActivityDO get(Long id){
		return volumeActivityDao.get(id);
	}
	
	@Override
	public List<VolumeActivityDO> list(Map<String, Object> map){
		return volumeActivityDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return volumeActivityDao.count(map);
	}
	
	@Override
	public int save(VolumeActivityDO volumeActivity,List<Object> list){
		if("2".equals(volumeActivity.getStatus())){
			volumeActivityDao.updateStatus();
		}
		int num=volumeActivityDao.save(volumeActivity);
		if (!list.isEmpty()) {
            for (Object obj : list) {
                if (obj != null) {
                	CouponDO couponDO = (CouponDO) obj;
                	couponDO.setCreatedate(new Date());
                	couponDO.setSva(volumeActivity.getId());
                	couponDao.save(couponDO);
                }
            }
        }
		return num ;
	}
	
	
	
	
	@Override
	public int stop(VolumeActivityDO volumeActivity){
		volumeActivity.setStatus("1");
		return volumeActivityDao.update(volumeActivity);
	}
	
	@Override
	public int start(VolumeActivityDO volumeActivity){
		volumeActivityDao.updateStatus();
		volumeActivity.setStatus("2");
		return volumeActivityDao.update(volumeActivity);
	}
	
	@Override
	public int update(VolumeActivityDO volumeActivity){
		return volumeActivityDao.update(volumeActivity);
	}
	
	@Override
	public int remove(Long id){
		return volumeActivityDao.remove(id);
	}
	
	@Override
	public int batchRemove(Long[] ids){
		return volumeActivityDao.batchRemove(ids);
	}
	
}
